package com.vercon.moensmart.mode;

import android.annotation.SuppressLint;
import android.content.Context;

import com.vercon.moensmart.R;
import com.vercon.moensmart.mode.response.HealthMeasure;

import java.util.ArrayList;

public class HealthMeasureTarget {

    /**
     * 体重
     */
    public final static String WEIGHT = "weight";

    public final static String BMI = "BMI";
    /**
     * 脂肪率
     */
    public final static String fat_rate = "fat_rate";
    /**
     * 蛋白质
     */
    public final static String protein = "protein";
    /**
     * 含水率
     */
    public final static String water_capacity = "water_capacity";
    /**
     * 内脏脂肪率
     */
    public final static String visceral_fat = "visceral_fat";
    /**
     * 骨骼肌
     */
    public final static String muscle_mass = "muscle_mass";
    /**
     * 骨量
     */
    public final static String bone_mass = "bone_mass";
    /**
     * 新陈代谢速率
     */
    public final static String metabolic_rate = "metabolic_rate";
    /**
     * 身体类型
     */
    public final static String body_type = "body_type";
    /**
     * 身体年龄
     */
    public final static String physical_age = "physical_age";

    public String type;

    private String title;

    private float value;

    private int gender;

    public HealthMeasureTarget(String type,float value,int gender){
        this.type = type;
        this.value = value;
        this.gender = gender;
    }

    @SuppressLint("DefaultLocale")
    public static String getName(String type){
        switch (type){
            case HealthMeasureTarget.WEIGHT:
                return "体重";
            case HealthMeasureTarget.BMI:
                return "BMI";
            case HealthMeasureTarget.fat_rate:
                return "脂肪率";
            case HealthMeasureTarget.protein:
                return "蛋白质";
            case HealthMeasureTarget.water_capacity :
                return "含水率";
            case HealthMeasureTarget.visceral_fat:
                return "内脏脂肪率";
            case HealthMeasureTarget.muscle_mass:
                return "肌肉量";
            case HealthMeasureTarget.bone_mass:
                return "含骨量";
            case HealthMeasureTarget.metabolic_rate :
                return "新陈代谢速率";
            case HealthMeasureTarget.body_type :
                return "身体类型";
            case HealthMeasureTarget.physical_age :
                return "身体年龄";
            default:
                return "";
        }
    }

    public String getTitle(Context context){
        switch (this.type){
            case WEIGHT:
                return "体重";
            case BMI:
                return "BMI";
            case fat_rate:
                return "脂肪率";
            case protein:
                return "蛋白质";
            case water_capacity :
                return "含水率";
            case visceral_fat:
                return "内脏脂肪率";
            case muscle_mass:
                return "肌肉量";
            case bone_mass:
                return "含骨量";
            case metabolic_rate :
                return "新陈代谢速率";
            case body_type :
                return "身体类型";
            case physical_age :
                return "身体年龄";
            default:
                return "";
        }
    }

    @SuppressLint("DefaultLocale")
    public String getValue(){
        switch (this.type){
            case WEIGHT:
                return String.format("%.1f",this.value);
            case BMI:
                return String.format("%.1f",this.value);
            case fat_rate:
                return String.format("%.1f",this.value);
            case protein:
                return String.format("%.1f",this.value);
            case water_capacity :
                return String.format("%.0f",this.value);
            case visceral_fat:
                return String.format("%.1f",this.value);
            case muscle_mass:
                return String.format("%.1f",this.value);
            case bone_mass:
                return String.format("%.1f",this.value);
            case metabolic_rate :
                return String.format("%.1f",this.value);
            case body_type :
                return getBodyType((int) this.value);
            case physical_age :
                return String.valueOf(Integer.valueOf(Math.round(this.value)));
            default:
                return "";
        }
    }

    public float getRealValue(){
        return this.value;
    }

    public String getUnit(){
        switch (this.type){
            case WEIGHT:
                return "kg";
            case BMI:
                return "";
            case fat_rate:
            case protein:
            case water_capacity :
            case visceral_fat:
            case muscle_mass:
                return "%";
            case bone_mass:
                return "公斤";
            case metabolic_rate :
                return "千卡";
            case body_type :
                return "";
            case physical_age :
                return "岁";
            default:
                return "";
        }
    }

    public boolean isNormal(){
        switch (this.type){
            case BMI:
            case fat_rate:
            case protein:
            case water_capacity :
            case visceral_fat:
            case muscle_mass:
            case bone_mass:
            case metabolic_rate :
                return getMin() <=this.value && getMax()>=this.value;
            case body_type :
                return "标准型".equals(getBodyType((int) this.value));
            case physical_age :
            default:
                return false;
        }
    }
    public static String getBodyType(int body_type){
        switch (body_type){
            case 1:
                return "肥胖型";
            case 2:
                return "偏胖型";
            case 3:
                return "标准型";
            case 4:
                return "偏瘦型";
            default:
                return "";
        }
    }

    public int getBodyTypePic(){
        switch ((int)this.value){
            case 1:
                return R.mipmap.ic_body_type_1;
            case 2:
                return R.mipmap.ic_body_type_2;
            case 3:
                return R.mipmap.ic_body_type_3;
            case 4:
                return R.mipmap.ic_body_type_4;
            default:
                return 0;
        }
    }

    public float getMin(){
        if(this.gender == 0){
            switch (this.type){
                case BMI:
                    return 18.65f;
                case fat_rate:
                    return 10f;
                case protein:
                    return 18.6f;
                case water_capacity :
                    return 47.2f;
                case visceral_fat:
                    return 0;
                case muscle_mass:
                    return 22.5f;
                case bone_mass:
                    return 2.24f;
                case metabolic_rate :
                    return 1320.0f;
                case body_type :
                case physical_age :
                default:
                    return 0;
            }
        }else {
            switch (this.type){
                case BMI:
                    return 18.5f;
                case fat_rate:
                    return 18f;
                case protein:
                    return 12.9f;
                case water_capacity :
                    return 41f;
                case visceral_fat:
                    return 0;
                case muscle_mass:
                    return 19.4f;
                case bone_mass:
                    return 1.86f;
                case metabolic_rate :
                    return 1319.0f;
                case body_type :
                case physical_age :
                default:
                    return 0;
            }
        }
    }

    public float getMax(){
        if(this.gender == 0){
            switch (this.type){
                case BMI:
                    return 23.9f;
                case fat_rate:
                    return 20f;
                case protein:
                    return 24.9f;
                case water_capacity :
                    return 70f;
                case visceral_fat:
                    return 9.9f;
                case muscle_mass:
                    return 39.0f;
                case bone_mass:
                    return 3.05f;
                case metabolic_rate :
                    return 2410.0f;
                case body_type :
                case physical_age :
                default:
                    return 0;
            }
        }else {
            switch (this.type){
                case BMI:
                    return 23.9f;
                case fat_rate:
                    return 28f;
                case protein:
                    return 21.3f;
                case water_capacity :
                    return 55.9f;
                case visceral_fat:
                    return 9.9f;
                case muscle_mass:
                    return 26.3f;
                case bone_mass:
                    return 2.54f;
                case metabolic_rate :
                    return 1485.0f;
                case body_type :
                case physical_age :
                default:
                    return 0;
            }
        }
    }

    public String getIsNormalTip(Context context){
        if(isNormal()){
            return "您的" + getTitle(context) + "正常，非常棒！";
        }else {
            return "您的" + getTitle(context) + "异常，请注意！";
        }
    }

    public static ArrayList<HealthMeasureTarget> getShowList(HealthMeasure.LogContent data){
        ArrayList<HealthMeasureTarget> dataList = new ArrayList<>();
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.BMI,data.bmi,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.fat_rate,data.fat_rate,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.protein,data.protein,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.water_capacity,data.water_capacity,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.visceral_fat, (float) data.visceral_fat,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.muscle_mass,data.muscle_mass,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.bone_mass,data.bone_mass,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.metabolic_rate,data.metabolic_rate,data.gender));
        dataList.add(new HealthMeasureTarget(HealthMeasureTarget.body_type,(float)data.body_type,data.gender));
        dataList.add(new HealthMeasureTarget(HealthMeasureTarget.physical_age,(float)data.physical_age,data.gender));
        return dataList;
    }
    public static ArrayList<HealthMeasureTarget> getShowListDialog(HealthMeasure.LogContent data){
        ArrayList<HealthMeasureTarget> dataList = new ArrayList<>();
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.WEIGHT,data.weight,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.BMI,data.bmi,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.fat_rate,data.fat_rate,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.protein,data.protein,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.water_capacity,data.water_capacity,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.visceral_fat, (float) data.visceral_fat,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.muscle_mass,data.muscle_mass,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.bone_mass,data.bone_mass,data.gender));
        dataList.add(new HealthMeasureTarget( HealthMeasureTarget.metabolic_rate,data.metabolic_rate,data.gender));
        dataList.add(new HealthMeasureTarget(HealthMeasureTarget.body_type,(float)data.body_type,data.gender));
        return dataList;
    }
}
